import Router from 'vue-router'
import Vue from 'vue'

Vue.use(Router)
const Home = () => import("views/home/Home.vue")
const Goods = () => import("views/goods/Goods.vue")
const Details = () => import("views/details/Details.vue")
const ShoppingCart = () => import("views/shoppingCart/ShoppingCart")
const Collect = () => import("views/collect/Collect")
const Order = () => import("views/order/Order")
const ConfirmOrder = () => import("views/confirmOrder/ConfirmOrder")
const About = () => import("views/about/About")



const routes = [{
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/goods',
    name: 'Goods',
    component: Goods
  },
  {
    path: '/goods/details',
    name: 'Details',
    component: Details
  },
  {
    path: '/about',
    name: 'About',
    component: About
  },
  {
    path: '/shoppingCart',
    name: 'ShoppingCart',
    component: ShoppingCart,
    meta: {
      requireAuth: true //需要验证登录状态
    }
  },
  {
    path: '/collect',
    name: 'Collect',
    component: Collect,
    meta: {
      requireAuth: true //需要验证登录状态
    }
  },
  {
    path: '/order',
    name: 'Order',
    component: Order,
    meta: {
      requireAuth: true //需要验证登录状态
    }
  },
  {
    path: '/confirmOrder',
    name: 'ConfirmOrder',
    component: ConfirmOrder,
    meta: {
      requireAuth: true //需要验证登录状态
    }
  },

]

const router = new Router({
  routes
})




// 对NavigationDuplicated（重复路由跳转）错误进行捕获
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)

}

export default router